package C027;

import java.util.PriorityQueue;

/**
 * ClassName: C03
 * Package: C027
 * Description:
 *
 * @Author BCXJ
 * @Create 2024/12/12 20:10
 * @Version 1.0
 * @Since 1.0
 */
public class C03 {


    public static void main(String[] args) {

//        int[] arr = {5,19,8,1};
        int[] arr = {1,1,1,1};
        System.out.println(halveArray(arr));
    }

    public static int halveArray(int[] nums) {
        PriorityQueue<Double> heap = new PriorityQueue<>((o1, o2) -> o2.compareTo(o1));
        long sum = 0;
        for (int i = 0; i < nums.length; i++) {
            heap.add((double)nums[i]);
            sum += nums[i];
        }
        double sum2 = sum;
        double mid = sum / 2D;
        int count = 0;
        while(sum2 >  mid) {
            Double poll = heap.poll();
            sum2 -= (poll / 2);
            heap.add(poll / 2);
            count ++;
        }
        return count;
    }
}
